function PlotHandle = GDADSplot(ChanNum,AnalysisNum,AnalysisType,XScale,YScale)
%GDADSplot(ChanNum,AnalysisNum,AnalysisType,XScale,YScale)
%Example: Plot(1)=GDADSplot(1,1,2,[20 2000],[1e-5 10])
% 
%GDADSplot - Plot a set of dynamic data analysis channels contained in the 
%   in GSFC Dynamic Analysis Data Structure (GDADS)and plot in the GSFC AETD plot format.
%
%Author: Donald R. Baker
%   ManTech International Corporation
%
%Created: July 14, 2002
%Current Release: April 22, 2005
%
%Purpose: GDADSplot function accepts a channel of data from the globally defined
%   data file in the GSFC Dynamic Analysis Data Structure (GDADS)
%   and generates a plot the GSFC AETD format.
%   GDADSplot function returns the Figure Handle after successful completion.
%
%Modified:  September 28, 2002
%Modified:  March 31, 2003
%   Case 0 - Y (Maximum) and Y (Minimum) determined over Plot Range
%       MaximumAmplitude=max(Y(XMinIndex:XMaxIndex));
%       MinimumAmplitude=min(Y(XMinIndex:XMaxIndex));
%Modified: April 01, 2003
%   PlotType argument removed from Function
%Modified: May 10, 2003
%   Corrected Plot format for Sine Magnetude vs Frequency Plotting (Case 4)
%       Phase Plot Removed - Only Magnitude vs Frequency Plot Generated
%Modified: August 13, 2003
%   Corrected frequency resolution calculation for Case 2, 3, 4, and 5
%           AnalysisResolution=(X(length(X)))/(length(X)-1);
%   Revised OverAllRMS calculation for Case 0, and 1
%           OverAllRms=std(Y(XMinIndex:XMaxIndex),1);
%   Corrected OverAllRMS calculation for Case 2
%           OverAllRms=sqrt(sum(Y(XMinIndex:XMaxIndex))*AnalysisResolution);
%   Changed selection criteria when AnalysisNum > 0 from first to last 
%           occurance of an analysis set containing Analysis Type n. 
%           AnalysisNum=AnalysisTypeIndex(length(AnalysisTypeIndex));
%   Changed all occurances of   
%           NumSamplesTotal=size(X); to NumSamples=length(X);
%   Deleted all occurances of
%           NumSamples=NumSamplesTotal(1,2);
%   Change to return Figure Handle from GDADSplot function
%           figure('Position',ScreenPosition); changed to     
%           PlotHandle=figure('Position',ScreenPosition);
%Modified: April 7, 2004
%   Added RunDescriptionLabel
%           RunDescriptionLabel=[Project.Test_Item.Descrip];
%   Modified TransLocationLabel
%           TransLocationLabel=[Project.Test_Item.Descrip];
%   Modified Case 4 AnalysisLabel
%           AnalysisLabel='Swept Sine Magnitude';
%
% Modified: April 22, 2005 by B. Ross
%
%   Routine reworked to remove redundancy in code and fix some problems with
%   plot scaling.  This GDADSplot routine now will plot one channel of data at a
%   time using the supplied plot scales.  The logic to set the plot scales was
%   moved to the print function in the Shell program.
%
%*******************************************************************************
%Function Parameters:
%   ChanNum:
%       Channel number of data in GDADS defined by Project.Test_Item.Run.Channel(ChanNum)
%
%   AnalysisNum:
%       Analysis number of data in GDADS defined by Project.Test_Item.Run.Channel(ChanNum).Analysis(AnalysisNum)
%
%   AnalysisType:
%           Analysis Type defined by AnalysisNum in GDADS defined by
%               Project.Test_Item.Run.Channel(ChanNum).Analysis(AnalysisNum).Type
%           1 = Time History
%           2 = PSD
%           3 = FRF - Frequency Response Function; H=(Ax/Gxy) where x=Response; y=Reference
%           4 = Swept Sine (Magnitude vs Frequency)
%           5 = Swept Sine FRF
%           6 = SRS
%           7 = 1/3 Octave
%           8 = Definition to be added
%
%   XScale:
%       Min and Max X Axis plot scale values.  Used for all plots in batch.
%
%   YScale:
%       Min and Max Y Axis plot scale values.  Used for all plots in batch.
%
global Project;

%  Load data from project structure
if (AnalysisType == 0 | AnalysisType == 1) % Time history data
    % Modified 14-Apr-2004 by CM: Convert single to double precision
    Y=double(Project.Test_Item.Run.Channel(ChanNum).Time_His);
    X=Project.Test_Item.Run.Time_Ref;
else % Analysis data
    Y=abs(Project.Test_Item.Run.Channel(ChanNum).Analysis(AnalysisNum).Ord); % This will handle real and complex data
    Yp=angle(Project.Test_Item.Run.Channel(ChanNum).Analysis(AnalysisNum).Ord)*180/pi; % Only gets used for FRF data types
    X=Project.Test_Item.Run.Channel(ChanNum).Analysis(AnalysisNum).Abs;
end

%  Set min and max index for data based on supplied plot X scale.  This will
%  keep a max/min value from being calculated for an X value that is out of
%  range of the plot scale.
templow = find(X >= XScale(1));
temphigh = find(X <= XScale(2));
XMinIndex = templow(1);
XMaxIndex = temphigh(length(temphigh));

%  Define General Plot Labels from GDADS
%  Create Run Number from Project.Test_Item.Run.ADF_File
ADFFile=Project.Test_Item.Run.ADF_File;
Period=strfind(ADFFile,'.');
RunNumberStr=ADFFile(Period-2:Period-1);
RunNumber=str2num(RunNumberStr);
TestDate=Project.Test_Item.Run.Test_Date;
EngUnits=Project.Test_Item.Run.Channel(ChanNum).EU;
%    ProjectLabel=['Project: ',Project.Name];
DateLabel=['Test Date: ',TestDate];
RunDescriptionLabel=[Project.Test_Item.Run.Descrip];
%    RunLabel=['Run ',num2str(RunNumber),' - ',Project.Test_Item.Run.Axis,' Axis ',...
%           Project.Test_Item.Run.Test_Type,' ',Project.Test_Item.Run.Test_Level];
ChanLabel=['DDAS Channel: ',num2str(ChanNum)];
TransLocationLabel=['Location: ',Project.Test_Item.Run.Channel(ChanNum).Trans_Loc,...
            ' (',Project.Test_Item.Run.Channel(ChanNum).Coordinate,...
            Project.Test_Item.Run.Channel(ChanNum).Direction,...
            Project.Test_Item.Run.Channel(ChanNum).Orientation,')'];
TransDescriptionLabel=['Transducer Type: ',Project.Test_Item.Run.Channel(ChanNum).Trans_Type,...
            ' S/N: ',Project.Test_Item.Run.Channel(ChanNum).Serial_Num];
LowPassFilter=['Low Pass Filter: ',num2str(Project.Test_Item.Run.Low_Pass),' Hz'];

%  Format Plot Figure Window
BottomBorderWidth = 10;
TopborderdWidth = 30;
set(0,'Units','pixels')
ScreenSize=get(0,'ScreenSize');
%       TimeDomainPlot=figure;
%       figure(TimeDomainPlot);
ScreenPosition=[BottomBorderWidth,1/4*ScreenSize(4) + BottomBorderWidth,...
7/8*ScreenSize(3) - 2*BottomBorderWidth,3/4*ScreenSize(4) - (TopborderdWidth + BottomBorderWidth)];
PlotHandle=figure('Position',ScreenPosition);
set(gcf,'PaperPosition',[.5,.5,10,7.5],'PaperOrientation','landscape');
datatext=axes('Position',[0 0 1 1], 'Visible','off');

%  Generate Plot Text
set(gcf, 'currentaxes', datatext);
%    Plot (datatext) - Left Side Text
ProjectLabel = [Project.Name, ' : ', Project.Test_Item.TI_Name];
text(.1,0.18,ProjectLabel,'HorizontalAlignment','Left','FontSize',10);
%text(.1,0.18,Project.Name,'HorizontalAlignment','Left','FontSize',10);
text(.1,0.16,RunDescriptionLabel,'HorizontalAlignment','Left','FontSize',10);
text(.1,0.14,TransLocationLabel,'HorizontalAlignment','Left','FontSize',10);        
text(.1,0.12,TransDescriptionLabel,'HorizontalAlignment','Left','FontSize',10);
%    Plot (datatext) - Right Side Text
text(.6,0.18,DateLabel,'HorizontalAlignment','Left','FontSize',10);          
text(.6,0.16,ChanLabel,'FontSize',10);
% text(.6,0.14,ResolutionLabel,'HorizontalAlignment','Left','FontSize',10);
text(.6,0.12,LowPassFilter,'HorizontalAlignment','Left','FontSize',10);
%    Plot (datatext) - NASA Identification           
text(.84,0.05,'NASA Goddard Space Flight Center','HorizontalAlignment','Center','FontSize',12);
text(.84,0.03,'Applied Engineering and Technology Directorate','HorizontalAlignment','Center','FontSize',10);
text(.84,0.01,'Test & Integration Vibration Test Facilities','HorizontalAlignment','Center','FontSize',8);
%
%Determine AnalysisType and Switch to Plot Section required by Analysis
switch AnalysisType
    case 0
        %Time History Plot of Orginal Time Domain Data: Linear X & Linear Y; X=Time Y=Magnitude
        % fprintf('Case 0: Time History Plot: Linear X & Linear Y; X=Time Y=Magnitude')
        AnalysisLabel='Time History';
%         text(.45,0.975,AnalysisLabel,'HorizontalAlignment','Center','FontSize',12);
        TimeStep=1/Project.Test_Item.Run.Sample_Rate;
        ResolutionLabel=['Resolution: ',num2str(TimeStep,'%7.6f'),' seconds'];
        MaximumAmplitude=max(Y(XMinIndex:XMaxIndex));
        MaximumAmplitudeLabel=num2str(MaximumAmplitude,'%+8.4g');
        MinimumAmplitude=min(Y(XMinIndex:XMaxIndex));
        MinimumAmplitudeLabel=num2str(MinimumAmplitude,'%+8.4g');
        MinMaxLabel01=['Max./Min Amplitudes:'];
        MinMaxLabel02=['     ',MaximumAmplitudeLabel,'/',MinimumAmplitudeLabel,' ',EngUnits,' pk'];
        %Generate Plot Graphics
        dataplot=axes('Position',[.1 .25 .6875 .6875]);
        set(gcf,'currentaxes',dataplot);
        OverAllRms=std(Y(XMinIndex:XMaxIndex),1);
        OverAllRmsLabel=num2str(OverAllRms,'%8.4g');
        RmsLabel=['Overall RMS: ',OverAllRmsLabel,' ',EngUnits,'rms'];
        %  Plot data
%        plot(X,Y); axis([XScale YScale]); grid
        % Added 14-Sep-2012 by C. McLeod to override the fixed Y-axis scale
        % for all Time Histories
        plot(X,Y); axis([XScale -inf inf]); grid
        % Determine Engineering Unit of Displayed data
        dataEU = Project.Test_Item.Run.Channel(ChanNum).EU;
        ylab = make_EU_name(ChanNum);
        % Label Plot
        ylabel(strcat(ylab,'(',dataEU,')'));
        xlabel('Time (sec)','Fontsize',10);
        title(AnalysisLabel,'FontSize',12);
        %Plot (datatext) - Notes
        set(gcf, 'currentaxes', datatext);
        text(.85,0.9,'Notes:','HorizontalAlignment','Left','FontSize',10);
        text(.8,0.86,MinMaxLabel01,'HorizontalAlignment','Left','FontSize',10);
        text(.8,0.84,MinMaxLabel02,'HorizontalAlignment','Left','FontSize',10);
        text(.8,0.79,RmsLabel,'HorizontalAlignment','Left','FontSize',10);
        text(.8,0.73,ResolutionLabel,'HorizontalAlignment','Left','FontSize',10);
        hold off;
    case 1
        %Time History Plot of AnalysisType=1: Linear X & Linear Y; X=Time Y=Magnitude
        % fprintf('Case 1: Time History Plot: Linear X & Linear Y; X=Time Y=Magnitude\n')
        AnalysisLabel='Time History';
%         text(.45,0.975,AnalysisLabel,'HorizontalAlignment','Center','FontSize',12);
        TimeStep=1/Project.Test_Item.Sample_Rate;
        ResolutionLabel=['Resolution: ',num2str(TimeStep,'%7.6f'),' seconds'];
        MaximumAmplitude=max(Y(XMinIndex:XMaxIndex));
        MaximumAmplitudeLabel=num2str(MaximumAmplitude,'%+8.4g');
        MinimumAmplitude=min(Y(XMinIndex:XMaxIndex));
        MinimumAmplitudeLabel=num2str(MinimumAmplitude,'%+8.4g');
        MinMaxLabel01=['Max./Min Amplitudes:'];
        MinMaxLabel02=['     ',MaximumAmplitudeLabel,'/',MinimumAmplitudeLabel,' ',EngUnits,' pk'];        
        %Generate Plot Graphics
        dataplot=axes('Position',[.1 .25 .6875 .6875]);
        set(gcf,'currentaxes',dataplot);
        OverAllRms=std(Y(XMinIndex:XMaxIndex),1);
        OverAllRmsLabel=num2str(OverAllRms,'%8.4g');
        RmsLabel=['Overall RMS: ',OverAllRmsLabel,' ',EngUnits,'rms'];
        %  Plot data
        plot(X,Y); axis([XScale YScale]); grid
        % Determine Engineering Unit of Displayed data
        dataEU = Project.Test_Item.Run.Channel(ChanNum).EU;
        ylab = make_EU_name(ChanNum);
        %  Label plot
        ylabel(strcat(ylab,'(',dataEU,')'));
        xlabel('Time (sec)','Fontsize',10);
        title(AnalysisLabel,'FontSize',12);
        %Plot (datatext) - Notes
        set(gcf, 'currentaxes', datatext);
        text(.85,0.9,'Notes:','HorizontalAlignment','Left','FontSize',10);
        text(.8,0.86,MinMaxLabel01,'HorizontalAlignment','Left','FontSize',10);
        text(.8,0.84,MinMaxLabel02,'HorizontalAlignment','Left','FontSize',10);
        text(.8,0.79,RmsLabel,'HorizontalAlignment','Left','FontSize',10);
        text(.8,0.73,ResolutionLabel,'HorizontalAlignment','Left','FontSize',10);
        hold off;
    case 2
        %PSD Plot of AnalysisType=2: Default: Log X & Log Y; X=Frequency Y=Magnitude^2
        % fprintf('Case 2: PSD Plot of AnalysisType=2: Default: Log X & Log Y; X=Frequency Y=Magnitude^2\n')
        AnalysisLabel='Power Spectral Density (PSD)';
%         text(.45,0.975,AnalysisLabel,'HorizontalAlignment','Center','FontSize',12);
        % AnalysisResolution=(X(length(X)))/(length(X)-1);
        AnalysisResolution = X(length(X)) - X(length(X)-1);
        ResolutionLabel=['Resolution: ',num2str(AnalysisResolution,'%5.2f'),' Hz'];
        MaximumAmplitude=max(Y(XMinIndex:XMaxIndex));
        MaxAmpXLabel = num2str(X(find(Y==MaximumAmplitude)),'%7.2f');
        MaximumAmplitudeLabel=num2str(MaximumAmplitude,'%4.3e');
        MinimumAmplitude=min(Y(XMinIndex:XMaxIndex));
        MinAmpXLabel = num2str(X(find(Y==MinimumAmplitude)),'%7.2f');
        MinimumAmplitudeLabel=num2str(MinimumAmplitude,'%4.3e');
        MaxLabel01=['Maximum Amplitude:'];
        MaxLabel02=[MaximumAmplitudeLabel,' ',EngUnits,'^2/Hz',' @ ',MaxAmpXLabel,' Hz'];
        MinLabel01=['Minimum Amplitude:'];
        MinLabel02=[MinimumAmplitudeLabel,' ',EngUnits,'^2/Hz',' @ ',MinAmpXLabel,' Hz'];
        %Generate Plot Graphics
        dataplot=axes('Position',[.1 .25 .6875 .6875]);
        set(gcf,'currentaxes',dataplot);
        OverAllRms=sqrt(sum(Y(XMinIndex:XMaxIndex))*AnalysisResolution);
        OverAllRmsLabel=num2str(OverAllRms,'%8.4g');
        RmsLabel=['Overall RMS: ',OverAllRmsLabel,' ',EngUnits,'rms'];
        %  Plot data
        loglog(X,Y); axis([XScale YScale]), grid
        % Label Plot
        yaxislabel = [EngUnits '^2/Hz']; % Changed 4/11 by BPR to fix axis label problem when units change from channel to channel
        ylabel(yaxislabel,'FontSize',10);
        xlabel('Frequency (Hz)','FontSize',10);
        title(AnalysisLabel, 'FontSize',12);
        %Plot (datatext) - Notes
        set(gcf, 'currentaxes', datatext);
        text(.85,0.9,'Notes:','HorizontalAlignment','Left','FontSize',10,'FontWeight','bold');
        text(.8,0.86,MaxLabel01,'HorizontalAlignment','Left','FontSize',10,'FontWeight','bold');
        text(.8,0.83,MaxLabel02,'HorizontalAlignment','Left','FontSize',10);
        text(.8,0.80,MinLabel01,'HorizontalAlignment','Left','FontSize',10,'FontWeight','bold');
        text(.8,0.77,MinLabel02,'HorizontalAlignment','Left','FontSize',10);
        text(.8,0.72,RmsLabel,'HorizontalAlignment','Left','FontSize',10);
        text(.8,0.67,ResolutionLabel,'HorizontalAlignment','Left','FontSize',10);
        hold off;
    case 3
        %Freq. Response Function w/Phase (BODE) Plot of AnalysisType=3: 
        %   Default: Log X & Log Y; X=Frequency Y=Magnetude & Yp=Phase=+/-180 Degrees
        % fprintf('Case 3: Freq. Response Function w/Phase (BODE) Plot of AnalysisType=3')
        AnalysisLabel='Transfer Function';
%         text(.45,0.975,AnalysisLabel,'HorizontalAlignment','Center','FontSize',12);
        AnalysisResolution=(X(length(X)))/(length(X)-1);
        ResolutionLabel=['Resolution: ',num2str(AnalysisResolution,'%5.2f'),' Hz'];
        ReferenceLabel=['Reference Channel: ',num2str(Project.Test_Item.Run.Channel(ChanNum).Analysis(AnalysisNum).RefChan)];
        MaximumAmplitude=max(Y(XMinIndex:XMaxIndex));
        MaxAmpXLabel = num2str(X(find(Y==MaximumAmplitude)),'%7.2f');
        MaximumAmplitudeLabel=num2str(MaximumAmplitude,'%5.2g');
        MinimumAmplitude=min(Y(XMinIndex:XMaxIndex));
        MinAmpXLabel = num2str(X(find(Y==MinimumAmplitude)),'%7.2f');
        MinimumAmplitudeLabel=num2str(MinimumAmplitude,'%5.2g');
        MaxLabel01=['Maximum Amplitude:'];
        MaxLabel02=[MaximumAmplitudeLabel,' ',EngUnits,' @ ',MaxAmpXLabel,' Hz'];
        MinLabel01=['Minimum Amplitude:'];
        MinLabel02=[MinimumAmplitudeLabel,' ',EngUnits,' @ ',MinAmpXLabel,' Hz'];
        %Generate Plot Graphics
        dataplot=axes('Position',[.1 .25 .6875 .525]); % Magnitude axes
        phaseplot=axes('Position',[.1 .8325 .6875 .125]); % Phase axes
        %  Plot Magnitude data
        set(gcf,'currentaxes',dataplot)
        loglog(X(XMinIndex:XMaxIndex),Y(XMinIndex:XMaxIndex)); axis([XScale YScale]); grid;
        % Label Magnitude Plot
%         ylab = ['Transfer Function Magnitude'];
        ylabel('Magnitude','FontSize',10);
        xlabel('Frequency (Hz)','FontSize',10);
%         title(AnalysisLabel, 'FontSize',12);
        %  Plot Phase data
        set(gcf,'currentaxes',phaseplot)
        semilogx(X(XMinIndex:XMaxIndex),Yp(XMinIndex:XMaxIndex)), axis([XScale,-180,180]), grid           
        % Label Phase Plot
        ylabel('Phase (Deg.)','Fontsize',10);
%         xlabel('Frequency (Hz)','FontSize',10);
        title(AnalysisLabel,'FontSize',12);
        %Plot (datatext) - Notes
        set(gcf, 'currentaxes', datatext);
        text(.85,0.75,'Notes:','HorizontalAlignment','Left','FontSize',10,'FontWeight','bold');
        text(.8,0.71,MaxLabel01,'HorizontalAlignment','Left','FontSize',10,'FontWeight','bold');
        text(.8,0.69,MaxLabel02,'HorizontalAlignment','Left','FontSize',10);
        text(.8,0.66,MinLabel01,'HorizontalAlignment','Left','FontSize',10,'FontWeight','bold');
        text(.8,0.63,MinLabel02,'HorizontalAlignment','Left','FontSize',10);
        text(.8,0.58,ResolutionLabel,'HorizontalAlignment','Left','FontSize',10);
        text(.6,0.14,ReferenceLabel,'HorizontalAlignment','Left','FontSize',10);
        hold off;
    case 4
        %Swept Sine Magnitude vs Frequency Plot of AnalysisType=4: 
        %   Default: Log X & Log Y; X=Frequency Y=Magnetude
        % fprintf('Swept Sine Magnitude vs Frequency Plot of AnalysisType=4')
        AnalysisLabel='Swept Sine Magnitude';
%         text(.45,0.975,AnalysisLabel,'HorizontalAlignment','Center','FontSize',12);
        AnalysisResolution=(X(length(X)))/(length(X)-1);
        ResolutionLabel=['Resolution: ',num2str(AnalysisResolution,'%4.1f'),' Hz'];
        MaximumAmplitude=max(Y(XMinIndex:XMaxIndex));
        MaxAmpXLabel = num2str(X(find(Y==MaximumAmplitude)),'%7.2f');
        MaximumAmplitudeLabel=num2str(MaximumAmplitude,'%5.2g');
        MinimumAmplitude=min(Y(XMinIndex:XMaxIndex));
        MinAmpXLabel = num2str(X(find(Y==MinimumAmplitude)),'%7.2f');
        MinimumAmplitudeLabel=num2str(MinimumAmplitude,'%5.2g');
        MaxLabel01=['Maximum Amplitude:'];
        MaxLabel02=[MaximumAmplitudeLabel,' ',EngUnits,' @ ',MaxAmpXLabel,' Hz'];
        MinLabel01=['Minimum Amplitude:'];
        MinLabel02=[MinimumAmplitudeLabel,' ',EngUnits,' @ ',MinAmpXLabel,' Hz'];
        %Generate Plot Graphics
        dataplot=axes('Position',[.1 .25 .6875 .6875]);
        % Plot data
        set(gcf,'currentaxes',dataplot)
        loglog(X,Y), axis([XScale YScale]), grid         
        % Determine Engineering Unit of Displayed data
        dataEU = Project.Test_Item.Run.Channel(ChanNum).EU;
        ylab = make_EU_name(ChanNum);
        %  Label plot
        ylabel(strcat(ylab,'(',dataEU,')'));
        xlabel('Frequency (Hz)','Fontsize',10);
        title(AnalysisLabel,'FontSize',12);
        %Plot (datatext) - Notes
        set(gcf, 'currentaxes', datatext);
        text(.85,0.9,'Notes:','HorizontalAlignment','Left','FontSize',10,'FontWeight','bold');
        text(.8,0.86,MaxLabel01,'HorizontalAlignment','Left','FontSize',10,'FontWeight','bold');
        text(.8,0.83,MaxLabel02,'HorizontalAlignment','Left','FontSize',10);
        text(.8,0.80,MinLabel01,'HorizontalAlignment','Left','FontSize',10,'FontWeight','bold');
        text(.8,0.77,MinLabel02,'HorizontalAlignment','Left','FontSize',10);
        hold off;
    case 5
        %Swept Sine Freq. Response Function w/Phase (BODE) Plot of AnalysisType=5: 
        %   Default: Log X & Log Y; X=Frequency Y=Magnetude & Yp=Phase=+/-180 Degrees
        AnalysisLabel='Frequency Response Function (FRF)';
%         text(.45,0.975,AnalysisLabel,'HorizontalAlignment','Center','FontSize',12);
        AnalysisResolution=(X(length(X)))/(length(X)-1);
        ResolutionLabel=['Resolution: ',num2str(AnalysisResolution,'%4.1f'),' Hz'];
        ReferenceLabel=['Reference Channel: ',num2str(Project.Test_Item.Run.Channel(ChanNum).Analysis(AnalysisNum).RefChan)];
        MaximumAmplitude=max(Y(XMinIndex:XMaxIndex));
        % Modified 6-Dec-2006 : C.McLeod
        MaxIndex = find(Y==MaximumAmplitude);
        if length(MaxIndex) > 1
            MaxIndex = MaxIndex(1);
        end
        MaxAmpXLabel = num2str(X(MaxIndex),'%7.2f');
        MaximumAmplitudeLabel=num2str(MaximumAmplitude,'%5.2g');
        MinimumAmplitude=min(Y(XMinIndex:XMaxIndex));
        MinIndex = find(Y==MinimumAmplitude);
        if length(MinIndex) > 1
            MinIndex = MinIndex(1);
        end
        MinAmpXLabel = num2str(X(MinIndex),'%7.2f');
        MinimumAmplitudeLabel=num2str(MinimumAmplitude,'%5.2g');
        MaxLabel01=['Maximum Amplitude:'];
        MaxLabel02=[MaximumAmplitudeLabel,' ',EngUnits,' @ ',MaxAmpXLabel,' Hz'];
        MinLabel01=['Minimum Amplitude:'];
        MinLabel02=[MinimumAmplitudeLabel,' ',EngUnits,' @ ',MinAmpXLabel,' Hz'];
        %Generate Plot Graphics
        dataplot=axes('Position',[.1 .25 .6875 .525]); % Magnitude axes
        phaseplot=axes('Position',[.1 .8325 .6875 .125]); % Phase axes
        % Plot Magnitude data
        set(gcf,'currentaxes',dataplot)
        loglog(X(XMinIndex:XMaxIndex),Y(XMinIndex:XMaxIndex)); axis([XScale YScale]); grid;
        % Label Magnitude plot
%         ylab = ['Magnitude'];
        ylabel('Magnitude','FontSize',10);
        xlabel('Frequency (Hz)','FontSize',10);
%         title(AnalysisLabel,'FontSize',12);
        % Plot Phase data
        set(gcf,'currentaxes',phaseplot)
        semilogx(X(XMinIndex:XMaxIndex),Yp(XMinIndex:XMaxIndex)); axis([XScale,-180,180]); grid;           
        % Label Phase plot
        ylabel('Phase (Deg.)','Fontsize',10);
%         xlabel('Frequency (Hz)','Fontsize',10);
        title(AnalysisLabel,'FontSize',12);
        %Plot (datatext) - Notes
        set(gcf, 'currentaxes', datatext);
        text(.85,0.75,'Notes:','HorizontalAlignment','Left','FontSize',10,'FontWeight','bold');
        text(.8,0.71,MaxLabel01,'HorizontalAlignment','Left','FontSize',10,'FontWeight','bold');
        text(.8,0.69,MaxLabel02,'HorizontalAlignment','Left','FontSize',10);
        text(.8,0.66,MinLabel01,'HorizontalAlignment','Left','FontSize',10,'FontWeight','bold');
        text(.8,0.63,MinLabel02,'HorizontalAlignment','Left','FontSize',10);
        text(.6,0.14,ReferenceLabel,'HorizontalAlignment','Left','FontSize',10);
        hold off;
    case 6
        %Shock Response Spectra (SRS) of AnalysisType=6: 
        %   Default: (SRS) : Log X & Log Y; X=Frequency Y=Magnetude
        % fprintf('Shock Response Spectra (SRS) of AnalysisType=6\n')
        AnalysisLabel='Shock Response Spectra (SRS)';
%         text(.45,0.975,AnalysisLabel,'HorizontalAlignment','Center','FontSize',12);
%         AnalysisResolution=(Project.Test_Item.Run.Sample_Rate/(NumSamples-1));
%         ResolutionLabel=['Resolution: ',num2str(AnalysisResolution,'%4.1f'),' Hz'];
        MaximumAmplitude=max(Y(XMinIndex:XMaxIndex));
        MaxAmpXLabel = num2str(X(find(Y==MaximumAmplitude)),'%7.2f');
        MaximumAmplitudeLabel=num2str(MaximumAmplitude,'%4.3e');
        MinimumAmplitude=min(Y(XMinIndex:XMaxIndex));
        MinAmpXLabel = num2str(X(find(Y==MinimumAmplitude)),'%7.2f');
        MinimumAmplitudeLabel=num2str(MinimumAmplitude,'%4.3e');
        MaxLabel01=['Maximum Amplitude:'];
        MaxLabel02=[MaximumAmplitudeLabel,' ',EngUnits,' @ ',MaxAmpXLabel,' Hz'];
        MinLabel01=['Minimum Amplitude:'];
        MinLabel02=[MinimumAmplitudeLabel,' ',EngUnits,' @ ',MinAmpXLabel,' Hz'];
        %Generate Plot Graphics
        dataplot=axes('Position',[.1 .25 .6875 .6875]);
        set(gcf,'currentaxes',dataplot);
        %  Plot data
        loglog(X,Y), axis([XScale YScale]), grid;
        % Determine Engineering Unit of Displayed data
        dataEU = Project.Test_Item.Run.Channel(ChanNum).EU;
        ylab = make_EU_name(ChanNum);
        % Label plot
        ylabel(strcat(ylab,'(',dataEU,')'));
        xlabel('Frequency (Hz)','Fontsize',10);
        title(AnalysisLabel,'FontSize',12);
        %Plot (datatext) - Notes
        set(gcf, 'currentaxes', datatext);
        text(.85,0.9,'Notes:','HorizontalAlignment','Left','FontSize',10,'FontWeight','bold');
        text(.8,0.86,MaxLabel01,'HorizontalAlignment','Left','FontSize',10,'FontWeight','bold');
        text(.8,0.83,MaxLabel02,'HorizontalAlignment','Left','FontSize',10);
        text(.8,0.80,MinLabel01,'HorizontalAlignment','Left','FontSize',10,'FontWeight','bold');
        text(.8,0.77,MinLabel02,'HorizontalAlignment','Left','FontSize',10);
%            text(.8,0.81,RmsLabel,'HorizontalAlignment','Left','FontSize',10);           
        hold off;
    end % switch AnalysisType
% =========================================================================
function eu_name = make_EU_name(ChanNum)
global Project;

dataEU = upper(Project.Test_Item.Run.Channel(ChanNum).EU);
switch dataEU
    case{'G'}
        eu_name = 'Acceleration';
    case{'UE'}
        eu_name = 'Strain';
    case{'LBS', 'LB'}
        eu_name = 'Force';
    case{'V', 'VT', 'VLTS', 'VOLTS'}
        eu_name = 'Volts';
    case{'PSI'}
        eu_name = 'Sound Pressure Level';
    case{'IN-LBS', 'IN-LB'}
        eu_name = 'Moment';
    case{'DEG', 'DEGREES'}
        eu_name = 'Phase';
    case{'IN/S', 'IPS'};
        eu_name = 'Velocity';
    case{'IN/SEC/SEC'};
        eu_name = 'Acceleration';
    case{'IN'};
        eu_name = 'Displacement';
    otherwise
        eu_name = 'Unknown Units';
end
